<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: actsColorFollowingExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.1</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('actsColorFollowingExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">actsColorFollowingExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Connects to the ACTS program, and uses an <a class="el" href="classArAction.html" title="Base class for actions. ">ArAction</a> subclass to drive the robot towards the largest detected blob.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Chase is an action that moves the robot toward the largest blob that</span></div><div class="line"><span class="comment">// appears in it&#39;s current field of view.</span></div><div class="line"><span class="keyword">class </span>Chase : <span class="keyword">public</span> <a name="_a0"></a><a class="code" href="classArAction.html">ArAction</a></div><div class="line">{</div><div class="line">  </div><div class="line"><span class="keyword">public</span>:</div><div class="line">  </div><div class="line">  <span class="comment">// The state of the chase action</span></div><div class="line">  <span class="keyword">enum</span> State {</div><div class="line">    NO_TARGET,      <span class="comment">// There is no target in view</span></div><div class="line">    TARGET,         <span class="comment">// This is a target in view</span></div><div class="line">  };</div><div class="line"></div><div class="line">  <span class="comment">// Constructor</span></div><div class="line">  Chase(<a name="_a1"></a><a class="code" href="classArACTS__1__2.html">ArACTS_1_2</a> *acts, <a name="_a2"></a><a class="code" href="classArVCC4.html">ArVCC4</a> *camera);</div><div class="line">  </div><div class="line">  <span class="comment">// Destructor</span></div><div class="line">  ~Chase(<span class="keywordtype">void</span>);</div><div class="line">  </div><div class="line">  <span class="comment">// The action</span></div><div class="line">  <a name="_a3"></a><a class="code" href="classArActionDesired.html">ArActionDesired</a> *<a name="a4"></a><a class="code" href="classArAction.html#a900675ede8563489ccc2e7e0934670bb">fire</a>(<a class="code" href="classArActionDesired.html">ArActionDesired</a> currentDesired);</div><div class="line"></div><div class="line">  <span class="comment">// Set the ACTS channel that we want to get blob info from</span></div><div class="line">  <span class="keywordtype">bool</span> setChannel(<span class="keywordtype">int</span> channel);</div><div class="line"></div><div class="line">  <span class="comment">// Return the current state of this action</span></div><div class="line">  State getState(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> myState; }</div><div class="line"></div><div class="line">  <span class="comment">// Height and width of pixels from frame-grabber</span></div><div class="line">  <span class="keyword">enum</span> {</div><div class="line">    WIDTH = 160,</div><div class="line">    HEIGHT = 120</div><div class="line">  };</div><div class="line"></div><div class="line"><span class="keyword">protected</span>:</div><div class="line">  <a class="code" href="classArActionDesired.html">ArActionDesired</a> myDesired;</div><div class="line">  <a class="code" href="classArACTS__1__2.html">ArACTS_1_2</a> *myActs;</div><div class="line">  <a class="code" href="classArVCC4.html">ArVCC4</a> *myCamera;</div><div class="line">  <a name="_a5"></a><a class="code" href="classArTime.html">ArTime</a> myLastSeen;</div><div class="line">  State myState;</div><div class="line">  <span class="keywordtype">int</span> myChannel;</div><div class="line">  <span class="keywordtype">int</span> myMaxTime;</div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Constructor: Initialize the chase action</span></div><div class="line">Chase::Chase(<a class="code" href="classArACTS__1__2.html">ArACTS_1_2</a> *acts, <a class="code" href="classArVCC4.html">ArVCC4</a> *camera) :</div><div class="line">    <a name="a6"></a><a class="code" href="classArAction.html#a4341cda2464899c839e370b514af929b">ArAction</a>(<span class="stringliteral">&quot;Chase&quot;</span>, <span class="stringliteral">&quot;Chases the largest blob.&quot;</span>)</div><div class="line">{</div><div class="line">  myActs = acts;</div><div class="line">  myCamera = camera;</div><div class="line">  myChannel = 0;</div><div class="line">  myState = NO_TARGET;</div><div class="line">  setChannel(1);</div><div class="line">  myLastSeen.setToNow();</div><div class="line">  myMaxTime = 1000;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// Destructor</span></div><div class="line">Chase::~Chase(<span class="keywordtype">void</span>) {}</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// The chase action</span></div><div class="line"><a class="code" href="classArActionDesired.html">ArActionDesired</a> *Chase::fire(<a class="code" href="classArActionDesired.html">ArActionDesired</a> currentDesired)</div><div class="line">{</div><div class="line">  <a name="_a7"></a><a class="code" href="classArACTSBlob.html">ArACTSBlob</a> blob;</div><div class="line">  <a class="code" href="classArACTSBlob.html">ArACTSBlob</a> largestBlob;</div><div class="line"></div><div class="line">  <span class="keywordtype">bool</span> flag = <span class="keyword">false</span>;</div><div class="line"></div><div class="line">  <span class="keywordtype">int</span> numberOfBlobs;</div><div class="line">  <span class="keywordtype">int</span> blobArea = 10;</div><div class="line"></div><div class="line">  <span class="keywordtype">double</span> xRel, yRel;</div><div class="line"></div><div class="line">  <span class="comment">// Reset the desired action</span></div><div class="line">  myDesired.reset();</div><div class="line">  </div><div class="line">  numberOfBlobs = myActs-&gt;getNumBlobs(myChannel);</div><div class="line"></div><div class="line">  <span class="comment">// If there are blobs to be seen, set the time to now</span></div><div class="line">  <span class="keywordflow">if</span>(numberOfBlobs != 0)</div><div class="line">  {</div><div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; numberOfBlobs; i++)</div><div class="line">    {</div><div class="line">      myActs-&gt;getBlob(myChannel, i + 1, &amp;blob);</div><div class="line">      <span class="keywordflow">if</span>(blob.<a name="a8"></a><a class="code" href="classArACTSBlob.html#ae93d582aad025b14cb07da1c8f6fc254">getArea</a>() &gt; blobArea)</div><div class="line">      {</div><div class="line">        flag = <span class="keyword">true</span>;</div><div class="line">        blobArea = blob.<a class="code" href="classArACTSBlob.html#ae93d582aad025b14cb07da1c8f6fc254">getArea</a>();</div><div class="line">        largestBlob = blob;</div><div class="line">      }</div><div class="line">    }</div><div class="line"></div><div class="line">    myLastSeen.setToNow();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// If we have not seen a blob in a while...</span></div><div class="line">  <span class="keywordflow">if</span> (myLastSeen.mSecSince() &gt; myMaxTime)</div><div class="line">  {</div><div class="line">    <span class="keywordflow">if</span>(myState != NO_TARGET) <a name="a9"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a10"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Target Lost&quot;</span>);</div><div class="line">    myState = NO_TARGET;</div><div class="line">  }</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">  {</div><div class="line">    <span class="comment">// If we see a blob and haven&#39;t seen one before..</span></div><div class="line">    <span class="keywordflow">if</span>(myState != TARGET) {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Target Aquired&quot;</span>);</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;(Using channel %d with %d blobs)&quot;</span>, myChannel, numberOfBlobs);</div><div class="line">    }</div><div class="line">    myState = TARGET;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span>(myState == TARGET &amp;&amp; flag == <span class="keyword">true</span>)</div><div class="line">  { </div><div class="line">    <span class="comment">// Determine where the largest blob&#39;s center of gravity</span></div><div class="line">    <span class="comment">// is relative to the center of the camera</span></div><div class="line">    xRel = (double)(largestBlob.<a name="a11"></a><a class="code" href="classArACTSBlob.html#a5f6eb283420c455186090bd339c63289">getXCG</a>() - WIDTH/2.0)  / (double)WIDTH;</div><div class="line">    yRel = (double)(largestBlob.<a name="a12"></a><a class="code" href="classArACTSBlob.html#a713ba6721a03e97d7722db58c729e817">getYCG</a>() - HEIGHT/2.0) / (double)HEIGHT;</div><div class="line">      </div><div class="line">    <span class="comment">// Tilt the camera toward the blob</span></div><div class="line">    <span class="keywordflow">if</span>(!(<a name="a13"></a><a class="code" href="classArMath.html#a82f8be1c5071b6c35106200c18ca7907">ArMath::fabs</a>(yRel) &lt; .20))</div><div class="line">    {</div><div class="line">      <span class="keywordflow">if</span> (-yRel &gt; 0)</div><div class="line">        myCamera-&gt;tiltRel(1);</div><div class="line">      <span class="keywordflow">else</span></div><div class="line">        myCamera-&gt;tiltRel(-1);</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="comment">// Set the heading and velocity for the robot</span></div><div class="line">    <span class="keywordflow">if</span> (<a class="code" href="classArMath.html#a82f8be1c5071b6c35106200c18ca7907">ArMath::fabs</a>(xRel) &lt; .10)</div><div class="line">    {</div><div class="line">      myDesired.setDeltaHeading(0);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">    {</div><div class="line">      <span class="keywordflow">if</span> (<a class="code" href="classArMath.html#a82f8be1c5071b6c35106200c18ca7907">ArMath::fabs</a>(-xRel * 10) &lt;= 10)</div><div class="line">        myDesired.setDeltaHeading(-xRel * 10);</div><div class="line">      <span class="keywordflow">else</span> <span class="keywordflow">if</span> (-xRel &gt; 0)</div><div class="line">        myDesired.setDeltaHeading(10);</div><div class="line">      <span class="keywordflow">else</span></div><div class="line">        myDesired.setDeltaHeading(-10);</div><div class="line">     </div><div class="line">    }</div><div class="line"></div><div class="line">    myDesired.setVel(200);</div><div class="line">    <span class="keywordflow">return</span> &amp;myDesired;    </div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// If we have no target, then don&#39;t set any action and let lower priority</span></div><div class="line">  <span class="comment">// actions (e.g. stop) control the robot.</span></div><div class="line">  <span class="keywordflow">return</span> &amp;myDesired;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// Set the channel that the blob info will be obtained from</span></div><div class="line"><span class="keywordtype">bool</span> Chase::setChannel(<span class="keywordtype">int</span> channel)</div><div class="line">{</div><div class="line">  <span class="keywordflow">if</span> (channel &gt;= 1 &amp;&amp; channel &lt;= <a name="a14"></a><a class="code" href="classArACTS__1__2.html#abd29db5baf1b65fcb73019f664adc996a75ffa2bd0d4e4952f00f77c5ed3ea4b7">ArACTS_1_2::NUM_CHANNELS</a>)</div><div class="line">  {</div><div class="line">    myChannel = channel;</div><div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">  }</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Callback to enable/disable the keyboard driving action</span></div><div class="line"><span class="keywordtype">void</span> toggleAction(<a class="code" href="classArAction.html">ArAction</a>* action)</div><div class="line">{</div><div class="line">  <span class="keywordflow">if</span>(action-&gt;<a name="a15"></a><a class="code" href="classArAction.html#a72db278f558206fdec03cbc15ac72104">isActive</a>()) {</div><div class="line">    action-&gt;<a name="a16"></a><a class="code" href="classArAction.html#aeca3135308234a8224643541090bea2b">deactivate</a>();</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;%s action is now deactivated.&quot;</span>, action-&gt;<a name="a17"></a><a class="code" href="classArAction.html#a77fd754d342d7662090f462e27971e08">getName</a>());</div><div class="line">  }</div><div class="line">  <span class="keywordflow">else</span> {</div><div class="line">    action-&gt;<a name="a18"></a><a class="code" href="classArAction.html#a758f6d649620747c5fa743d4f7a8b53e">activate</a>();</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;%s action is now activated.&quot;</span>, action-&gt;<a class="code" href="classArAction.html#a77fd754d342d7662090f462e27971e08">getName</a>());</div><div class="line">  }</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Main function</span></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)</div><div class="line">{</div><div class="line">  <a name="a19"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a20"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line">  parser.<a name="a21"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line">  <a name="_a22"></a><a class="code" href="classArRobot.html">ArRobot</a> robot;</div><div class="line">  <a name="_a23"></a><a class="code" href="classArRobotConnector.html">ArRobotConnector</a> robotConnector(&amp;parser, &amp;robot);</div><div class="line">  <a name="_a24"></a><a class="code" href="classArLaserConnector.html">ArLaserConnector</a> laserConnector(&amp;parser, &amp;robot, &amp;robotConnector);</div><div class="line"></div><div class="line">  <span class="comment">// Sonar for basic obstacle avoidance</span></div><div class="line">  <a name="_a25"></a><a class="code" href="classArSonarDevice.html">ArSonarDevice</a> sonar;</div><div class="line"></div><div class="line">  <span class="comment">// The camera (Cannon VC-C4) PTZ control</span></div><div class="line">  <span class="comment">// TODO replace with ArPTZConnector for other camera types</span></div><div class="line">  <a class="code" href="classArVCC4.html">ArVCC4</a> vcc4 (&amp;robot);</div><div class="line"></div><div class="line">  <span class="comment">// Connect to the robot, get some initial data from it such as type and name,</span></div><div class="line">  <span class="comment">// and then load parameter files for this robot.</span></div><div class="line">  <span class="keywordflow">if</span>(!robotConnector.<a name="a26"></a><a class="code" href="classArRobotConnector.html#ab192ac393d9cc1e5b61b1a82b08d085d">connectRobot</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a27"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;actsColorFollowingExample: Could not connect to the robot.&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span>(parser.<a name="a28"></a><a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">    {</div><div class="line">        <span class="comment">// -help not given</span></div><div class="line">        <a name="a29"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">        <a name="a30"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (!<a name="a31"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || !parser.<a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">  }</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;actsColorFollowingExample: Connected to robot.&quot;</span>);</div><div class="line"></div><div class="line">  robot.<a name="a32"></a><a class="code" href="classArRobot.html#a3c3d878cfd11a2ef91230005a83bfcaa">runAsync</a>(<span class="keyword">true</span>);</div><div class="line"></div><div class="line">  <span class="comment">// Connect to laser(s) as defined in parameter files.</span></div><div class="line">  <span class="comment">// (Some flags are available as arguments to connectLasers() to control error behavior and to control which lasers are put in the list of lasers stored by ArRobot. See docs for details.)</span></div><div class="line">  <span class="keywordflow">if</span>(!laserConnector.<a name="a33"></a><a class="code" href="classArLaserConnector.html#ab97ce6a5fedebf44526773bc674b970e">connectLasers</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;Warning: Could not connect to configured lasers. &quot;</span>);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// A key handler to take input from keyboard</span></div><div class="line">  <a name="_a34"></a><a class="code" href="classArKeyHandler.html">ArKeyHandler</a> keyHandler;</div><div class="line">  <a name="a35"></a><a class="code" href="classAria.html#a9e5496a4ec2c379c8e18706922b57cc1">Aria::setKeyHandler</a>(&amp;keyHandler);</div><div class="line"></div><div class="line">  <span class="comment">// ACTS, for tracking blobs of color</span></div><div class="line">  <a class="code" href="classArACTS__1__2.html">ArACTS_1_2</a> acts;</div><div class="line"></div><div class="line">  <span class="comment">// Robot motion limiter actions (if obstacles are detected by sonar or laser)</span></div><div class="line">  <a name="_a36"></a><a class="code" href="classArActionLimiterForwards.html">ArActionLimiterForwards</a> limiter(<span class="stringliteral">&quot;speed limiter near&quot;</span>, 350, 800, 200);</div><div class="line">  <a class="code" href="classArActionLimiterForwards.html">ArActionLimiterForwards</a> limiterFar(<span class="stringliteral">&quot;speed limiter far&quot;</span>, 400, 1250, 300);</div><div class="line">  <a name="_a37"></a><a class="code" href="classArActionLimiterBackwards.html">ArActionLimiterBackwards</a> backwardsLimiter;</div><div class="line">  <a name="_a38"></a><a class="code" href="classArActionConstantVelocity.html">ArActionConstantVelocity</a> stop(<span class="stringliteral">&quot;stop&quot;</span>, 0);</div><div class="line">  <span class="comment">//ArActionConstantVelocity backup(&quot;backup&quot;, -200);</span></div><div class="line">  </div><div class="line"></div><div class="line">  <span class="comment">// The color following action, defined above</span></div><div class="line">  Chase chase(&amp;acts, &amp;vcc4);</div><div class="line"></div><div class="line">  <span class="comment">// Keyboard teleoperation action</span></div><div class="line">  <a name="_a39"></a><a class="code" href="classArActionKeydrive.html">ArActionKeydrive</a> keydriveAction;</div><div class="line"></div><div class="line">  <span class="comment">// Use the &quot;a&quot; key to activate/deactivate keydrive mode</span></div><div class="line">  keyHandler.<a name="a40"></a><a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;a&#39;</span>, <span class="keyword">new</span> <a name="_a41"></a><a class="code" href="classArGlobalFunctor1.html">ArGlobalFunctor1&lt;ArAction*&gt;</a>(&amp;toggleAction, &amp;keydriveAction));</div><div class="line"></div><div class="line">  <span class="comment">// Let Aria know about the key handler</span></div><div class="line">  <a class="code" href="classAria.html#a9e5496a4ec2c379c8e18706922b57cc1">Aria::setKeyHandler</a>(&amp;keyHandler);</div><div class="line"></div><div class="line">  <span class="comment">// Add the key handler to the robot</span></div><div class="line">  robot.<a name="a42"></a><a class="code" href="classArRobot.html#ab4ea516667d2358f35b435d97b616ab1">attachKeyHandler</a>(&amp;keyHandler);</div><div class="line"></div><div class="line">  robot.<a name="a43"></a><a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609">lock</a>();</div><div class="line"></div><div class="line">  <span class="comment">// Add the sonar to the robot</span></div><div class="line">  robot.<a name="a44"></a><a class="code" href="classArRobot.html#a97d57b28549fdef851c00749a97cc776">addRangeDevice</a>(&amp;sonar);</div><div class="line"></div><div class="line">  <span class="comment">// Open a connection to ACTS</span></div><div class="line">  <span class="keywordflow">if</span>(!acts.<a name="a45"></a><a class="code" href="classArACTS__1__2.html#a5ce088ec894e3154910f0e5149668f80">openPort</a>(&amp;robot)) </div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;Error: Could not connect to ACTS... exiting.&quot;</span>);</div><div class="line">    keyHandler.<a name="a46"></a><a class="code" href="classArKeyHandler.html#ae75d46abeb802d1edac99400d387c404">restore</a>();</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(2);</div><div class="line">  }</div><div class="line">  </div><div class="line"></div><div class="line">  <span class="comment">// Initialize the camera</span></div><div class="line">  vcc4.<a name="a47"></a>init();</div><div class="line"></div><div class="line">  <span class="comment">// Artificially keep the robot from going too fast</span></div><div class="line">  robot.<a name="a48"></a><a class="code" href="classArRobot.html#ad6a5d53606c9ba9c8c796f908e2fc1a1">setAbsoluteMaxTransVel</a>(400);</div><div class="line"></div><div class="line">  <span class="comment">// Enable the motors</span></div><div class="line">  robot.<a name="a49"></a><a class="code" href="classArRobot.html#aceef80a6274fb34aafcc422e4b1778c1">comInt</a>(<a name="a50"></a><a class="code" href="classArCommands.html#a9a31f904a95bbc31d8b33c6637100cc4aa8d799cced5def80525936119963aad4">ArCommands::ENABLE</a>, 1);</div><div class="line">  </div><div class="line">  <span class="comment">// Turn off the amigobot sounds</span></div><div class="line">  robot.<a class="code" href="classArRobot.html#aceef80a6274fb34aafcc422e4b1778c1">comInt</a>(<a name="a51"></a><a class="code" href="classArCommands.html#a9a31f904a95bbc31d8b33c6637100cc4a7a256695b7937192e88c976d2fd106e5">ArCommands::SOUNDTOG</a>, 0);</div><div class="line"></div><div class="line">  <span class="comment">// Add the actions to the robot in descending order of importance.</span></div><div class="line">  robot.<a name="a52"></a><a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;limiter, 7);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;limiterFar, 6);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;backwardsLimiter, 5);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;keydriveAction, 4);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;chase, 3);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;stop, 1);</div><div class="line"></div><div class="line">  robot.<a name="a53"></a><a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491">unlock</a>();</div><div class="line"></div><div class="line">  <span class="comment">// Start with keydrive action disabled. Use the &#39;a&#39; key to turn it on.</span></div><div class="line">  keydriveAction.<a name="a54"></a>deactivate();</div><div class="line"></div><div class="line">  <span class="comment">// Run the robot processing cycle until the connection is lost</span></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Running. Train ACTS to detect a color to drive towards an object, or use &#39;a&#39; key to switch to keyboard driving mode.&quot;</span>);</div><div class="line">  </div><div class="line">  robot.<a name="a55"></a><a class="code" href="group__easy.html#ga95201be7c39b521983b51e6f5d9303e4">waitForRunExit</a>();</div><div class="line"></div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
